/*  process.h

    Symbols and structures for process management.

*/

/*
 *      C/C++ Run Time Library - Version 1.0
 *
 *      Copyright (c) 1987, 2002 by Borland Software Corporation
 *      All Rights Reserved.
 *
 */

/* $Revision: 1.4.8.1 $ */

#ifndef __PROCESS_H
#define __PROCESS_H

#ifndef ___STDDEF_H
#include <_defs.h>
#endif

/*  Modes available as first argument to the spawnxx functions. */
#define P_WAIT           0  /* child runs separately, parent waits until exit */
#define P_NOWAIT         1  /* both child & parent run concurrently */
#define P_OVERLAY        2  /* child replaces parent, parent no longer exists */
#define P_NOWAITO        3  /* ASYNCH,       toss RC    */
#define P_DETACH         4  /* DETACHED,     toss RC    */

/* MSC versions of the spawnxx modes */
#define _P_WAIT          0
#define _P_NOWAIT        1
#define _P_OVERLAY       2
#define _P_NOWAITO       3
/*      _P_DETACH           // This one conflicts with the Flag version below */

/* Flags that can be or'ed into the base spawnxx mode parameter */
#define _P_MASK         (0x07)  /* used to mask off the P_xxx values */

#define _P_DETACH       (0x0010) /* Run child as a detached process (or'able version of P_DETACH) */
#define _P_NEWCONSOLE   (0) /*(0x0020)*/ /* Run child in a new console window */
#define _P_NEWPROCGROUP (0) /*(0x0040)*/ /* Child is the root of a new Process Group */
#define _P_SUSPENDED    (0) /*(0x0080)*/ /* Child's main thread is created suspended */
#define _P_NOCLOSE      (0)      /* not applicible to Linux */
#define _P_NEWWIN16     (0)      /* not applicible to Linux */
#define _P_SHAREDWIN16  (0)      /* not applicible to Linux */
#define _P_DEFERRORMODE (0) /*(0x0800)*/ /* Child does not inherit error mode of parent */
#define _P_PRIO_IDLE    (0x1000) /* Run in IDLE priority class */
#define _P_PRIO_NORM    (0x2000) /* Run in NORMAL priority class */
#define _P_PRIO_HIGH    (0x4000) /* Run in HIGH priority class */
#define _P_PRIO_REAL    (0x8000) /* Run in REALTIME priority class */

#define WAIT_CHILD      (0)
#define WAIT_GRANDCHILD (1)

#ifdef __cplusplus
extern "C" {
#endif

/** Note: _cexit and _c_exit are not supported under Linux since there's
	no way to run all the atexit handlers without actually exiting.
*/
/* void   _cexit(void); */
/* void   _c_exit(void); */

int spawnl(int __mode, const char * __path, const char * __arg0, ...);
int spawnle(int __mode, const char * __path, const char * __arg0, ...);
int spawnlp(int __mode, const char * __path, const char * __arg0, ...);
int spawnlpe(int __mode, const char * __path, const char * __arg0, ...);
int spawnv(int __mode, const char * __path, const char * const * __argv);
int spawnve(int __mode, const char * __path, const char * const * __argv, const char * const * __env);
int spawnvp(int __mode, const char * __path, const char * const * __argv);
int spawnvpe(int __mode, const char * __path, const char * const * __argv, const char * const * __env);

int cwait(int *__term_stat, int __pid, int __action);

_INLFUNC int _cwait(int *__term_stat, int __pid, int __action)
{
	return cwait(__term_stat, __pid, __action);
}

#if defined(__MT__)

struct _thread_adoption_data_s { char __dummy; };
typedef struct _thread_adoption_data_s* _PTHREAD_ADOPTION_DATA;

void                          _unadopt_thread(_PTHREAD_ADOPTION_DATA __thd);
_PTHREAD_ADOPTION_DATA        _adopt_thread(void (_USERENTRY *__start_address)(void *),
                                                             void *__arglist,
                                                              int __free_flag);

unsigned long   _beginthread  (void (_USERENTRY *__start)(void *),
                                                unsigned __stksize, void *__arg);
unsigned long   _beginthreadNT(void (_USERENTRY *__start)(void *),
                                                unsigned __stksize, void *__arg,
                                                void *__security_attr,
                                                unsigned long __create_flags,
                                                unsigned long *__thread_id);

unsigned long   _beginthreadex(void *__security_attr,
                                                unsigned __stksize,
                                                unsigned (/* __stdcall */ *__start)(void *),
                                                void *__arg,
                                                unsigned __create_flags,
                                                unsigned *__thread_id);

void _endthread    (void);
void _endthreadex  (unsigned __thread_retval);

int __threadid(void);

#ifdef __linux__
/*
 * calling '__borland_use_pthreads' will cause the rtl to use pthreads
 * functions for handling thread local storage.  normally, the presence
 * of pthreads is queried at runtime and used only if present.
 * 
 * clients that wish to statically link to pthreads must call this
 * function to avoid runtime failures.
 */
void __borland_use_pthreads(void);
#endif

#endif  /* __MT__ */


#ifdef __cplusplus
}
#endif

#endif  /* __PROCESS_H */
